import { createRouter, createWebHashHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

const demos: RouteRecordRaw[] = [
    {
        path: '/olext',
        name: 'OlextDemo',
        component: () => import("@/layout/default/index.vue"),
        meta: {
            title: 'ol-ext 示例',
            isMenu: true
        },  
    },
    {
        path: '/demo',
        name: 'Demo',
        redirect: '/demo/draw',
        component: () => import("@/layout/default/index.vue"),
        meta: {
            title: 'OpenLayers 示例',
            to: '/demo'
        },
        children: [
            {
                path: 'accessible',
                name: 'Accessible',
                component: () => import("@/pages/openlayers/accessible.vue"),
                meta: {
                    title: '简单示例'
                }
            },
            {
                path: 'draw',
                name: 'Draw',
                component: () => import("@/pages/openlayers/draw.vue"),
                meta: {
                    title: '绘制几何图形'
                }
            }
        ]
    },
    {
        path: '/pkv',
        name: 'Pkv',
        redirect: '/pkv/draw',
        component: () => import("@/layout/map/MapLayout.vue"),
        meta: {
            title: '使用同一个地图'
        },
        children: [
            {
                path: 'draw',
                name: 'PkvDraw',
                component: () => import('@/pages/pk/draw.vue'),
                meta: {
                    title: '自由绘制'
                }
            },
            {
                path: 'marker',
                name: 'PkMarker',
                component: () => import('@/pages/pk/marker.vue'),
                meta: {
                    title: '标记点'
                }
            },
            {
                path: 'am',
                name: 'PkAggregatedAnnotation',
                component: () => import('@/pages/pk/aggregated_annotation.vue'),
                meta: {
                    title: '点聚合'
                }
            },
            {
                path: 'popup',
                name: 'PkPopup',
                component: () => import('@/pages/pk/popup.vue'),
                meta: {
                    title: '弹窗'
                }
            }
        ]
    }
]

export const list: RouteRecordRaw[] = [
    ...demos
]
/**
 * 路由集合
 */
const routes: RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/pkv'
    },
    ...list
]
const router = createRouter({
    routes,
    history: createWebHashHistory(),
    // to, from, savedPosition
    scrollBehavior: () => ({ left: 0, top: 0 })
})

export default router